<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Model;

class RcUser extends Model
{
	use HasDateTimeFormatter;
    protected $table = 'rc_user';
    protected $fillable = ['open_id','str_1','str_2','str_3','str_4','str_5','str_6','str_7','status','type'];



    public function wxMessage($open_id)
    {
        $data['thing6']['value'] = '品鉴官招募-0元试吃活动';
        $data['thing9']['value'] = '恭喜您成为品鉴官～';
        $data['thing10']['value'] = '点击填写地址，领取试吃商品吧～';
        $template = [
            'te_data' => $data,
            'template_id' => 'KSpbKkzbYsgMdnQ-H2GvfWCnPjyTY8hheIZq0JZE7oo',
            'open_id' => $open_id,
            'page' => '/packageTRY/pages/main/index'
        ];
        self::SendMessage($template);
    }


    public function SendMessage($template)
    {
        $token = env('WX_TOKEN');
        $client = new Client(['', 'timeout' => 5.0,]);
        //拿到微信access_token
        $response1 = $client->get('https://amxshop.yili.com/api/user/getAccessToken', ['headers' => ['accessToken' => $token]]);
        $data = json_decode($response1->getBody()->getContents());
        $wx_token = $data->data;
        \App\Jobs\WxMessage::dispatch($template, $wx_token, $client);


    }
}
